package ai.rpc.core.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author: mengyu
 * @Date: 2024/7/22
 * Mock代理类，返回默认测试数据
 */
public class MockServiceProxy implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Class<?> returnType = method.getReturnType();
        return getDefaultObject(returnType);
    }

    /**
     * 根据不同类型返回不同默认值
     *
     * @param type 方法类型
     * @return 默认值
     */
    private Object getDefaultObject(Class<?> type) {
        if (type == int.class) {
            return 0;
        } else if (type == short.class) {
            return (short) 0;
        } else if (type == boolean.class) {
            return false;
        } else if (type == long.class){
            return 0L;
        }
        else return null;
    }
}
